


<!DOCTYPE html>
<html id="htmlId">
<head>
  <title>Coverage Report > Player</title>
  <style type="text/css">
    @import "../../css/coverage.css";
    @import "../../css/highlight-idea.css";
  </style>
  <script type="text/javascript" src="../../js/highlight.pack.js"></script>
</head>

<body>
<div class="content">
<div class="breadCrumbs">
Current scope:     <a href="../../index.html">all classes</a>
    <span class="separator">|</span>
    <a href="../index.html">nl.tudelft.jpacman.level</a>
</div>

<h1>Coverage Summary for Class: Player (nl.tudelft.jpacman.level)</h1>

<table class="coverageStats">
<tr>
  <th class="name">Class</th>
<th class="coverageStat 
">
  Class, %
</th>
<th class="coverageStat 
">
  Method, %
</th>
<th class="coverageStat 
">
  Line, %
</th>
</tr>
<tr>
  <td class="name">Player</td>
<td class="coverageStat">
  <span class="percent">
    0%
  </span>
  <span class="absValue">
    (0/1)
  </span>
</td>
<td class="coverageStat">
  <span class="percent">
    0%
  </span>
  <span class="absValue">
    (0/8)
  </span>
</td>
<td class="coverageStat">
  <span class="percent">
    0%
  </span>
  <span class="absValue">
    (0/20)
  </span>
</td>
</tr>

</table>

<br/>
<br/>


<pre>
<div class="sourceCode" id="sourceCode"><i class="no-highlight">1</i>&nbsp;package nl.tudelft.jpacman.level;
<i class="no-highlight">2</i>&nbsp;
<i class="no-highlight">3</i>&nbsp;import java.util.Map;
<i class="no-highlight">4</i>&nbsp;
<i class="no-highlight">5</i>&nbsp;import nl.tudelft.jpacman.board.Direction;
<i class="no-highlight">6</i>&nbsp;import nl.tudelft.jpacman.board.Unit;
<i class="no-highlight">7</i>&nbsp;import nl.tudelft.jpacman.sprite.AnimatedSprite;
<i class="no-highlight">8</i>&nbsp;import nl.tudelft.jpacman.sprite.Sprite;
<i class="no-highlight">9</i>&nbsp;
<i class="no-highlight">10</i>&nbsp;/**
<i class="no-highlight">11</i>&nbsp; * A player operated unit in our game.
<i class="no-highlight">12</i>&nbsp; *
<i class="no-highlight">13</i>&nbsp; * @author Jeroen Roosen 
<i class="no-highlight">14</i>&nbsp; */
<i class="no-highlight">15</i>&nbsp;public class Player extends Unit {
<i class="no-highlight">16</i>&nbsp;
<i class="no-highlight">17</i>&nbsp;    /**
<i class="no-highlight">18</i>&nbsp;     * The amount of points accumulated by this player.
<i class="no-highlight">19</i>&nbsp;     */
<i class="no-highlight">20</i>&nbsp;    private int score;
<i class="no-highlight">21</i>&nbsp;
<i class="no-highlight">22</i>&nbsp;    /**
<i class="no-highlight">23</i>&nbsp;     * The animations for every direction.
<i class="no-highlight">24</i>&nbsp;     */
<i class="no-highlight">25</i>&nbsp;    private final Map&lt;Direction, Sprite&gt; sprites;
<i class="no-highlight">26</i>&nbsp;
<i class="no-highlight">27</i>&nbsp;    /**
<i class="no-highlight">28</i>&nbsp;     * The animation that is to be played when Pac-Man dies.
<i class="no-highlight">29</i>&nbsp;     */
<i class="no-highlight">30</i>&nbsp;    private final AnimatedSprite deathSprite;
<i class="no-highlight">31</i>&nbsp;
<i class="no-highlight">32</i>&nbsp;    /**
<i class="no-highlight">33</i>&nbsp;     * &lt;code&gt;true&lt;/code&gt; iff this player is alive.
<i class="no-highlight">34</i>&nbsp;     */
<i class="no-highlight">35</i>&nbsp;    private boolean alive;
<i class="no-highlight">36</i>&nbsp;
<i class="no-highlight">37</i>&nbsp;    /**
<i class="no-highlight">38</i>&nbsp;     * {@link Unit} iff this player died by collision, &lt;code&gt;null&lt;/code&gt; otherwise.
<i class="no-highlight">39</i>&nbsp;     */
<i class="no-highlight">40</i>&nbsp;    private Unit killer;
<i class="no-highlight">41</i>&nbsp;
<i class="no-highlight">42</i>&nbsp;    /**
<i class="no-highlight">43</i>&nbsp;     * Creates a new player with a score of 0 points.
<i class="no-highlight">44</i>&nbsp;     *
<i class="no-highlight">45</i>&nbsp;     * @param spriteMap
<i class="no-highlight">46</i>&nbsp;     *            A map containing a sprite for this player for every direction.
<i class="no-highlight">47</i>&nbsp;     * @param deathAnimation
<i class="no-highlight">48</i>&nbsp;     *            The sprite to be shown when this player dies.
<i class="no-highlight">49</i>&nbsp;     */
<b class="nc"><i class="no-highlight">50</i>&nbsp;    protected Player(Map&lt;Direction, Sprite&gt; spriteMap, AnimatedSprite deathAnimation) {</b>
<b class="nc"><i class="no-highlight">51</i>&nbsp;        this.score = 0;</b>
<b class="nc"><i class="no-highlight">52</i>&nbsp;        this.alive = true;</b>
<b class="nc"><i class="no-highlight">53</i>&nbsp;        this.sprites = spriteMap;</b>
<b class="nc"><i class="no-highlight">54</i>&nbsp;        this.deathSprite = deathAnimation;</b>
<b class="nc"><i class="no-highlight">55</i>&nbsp;        deathSprite.setAnimating(false);</b>
<i class="no-highlight">56</i>&nbsp;    }
<i class="no-highlight">57</i>&nbsp;
<i class="no-highlight">58</i>&nbsp;    /**
<i class="no-highlight">59</i>&nbsp;     * Returns whether this player is alive or not.
<i class="no-highlight">60</i>&nbsp;     *
<i class="no-highlight">61</i>&nbsp;     * @return &lt;code&gt;true&lt;/code&gt; iff the player is alive.
<i class="no-highlight">62</i>&nbsp;     */
<i class="no-highlight">63</i>&nbsp;    public boolean isAlive() {
<b class="nc"><i class="no-highlight">64</i>&nbsp;        return alive;</b>
<i class="no-highlight">65</i>&nbsp;    }
<i class="no-highlight">66</i>&nbsp;
<i class="no-highlight">67</i>&nbsp;    /**
<i class="no-highlight">68</i>&nbsp;     * Sets whether this player is alive or not.
<i class="no-highlight">69</i>&nbsp;     *
<i class="no-highlight">70</i>&nbsp;     * If the player comes back alive, the {@link killer} will be reset.
<i class="no-highlight">71</i>&nbsp;     *
<i class="no-highlight">72</i>&nbsp;     * @param isAlive
<i class="no-highlight">73</i>&nbsp;     *            &lt;code&gt;true&lt;/code&gt; iff this player is alive.
<i class="no-highlight">74</i>&nbsp;     */
<i class="no-highlight">75</i>&nbsp;    public void setAlive(boolean isAlive) {
<b class="nc"><i class="no-highlight">76</i>&nbsp;        if (isAlive) {</b>
<b class="nc"><i class="no-highlight">77</i>&nbsp;            deathSprite.setAnimating(false);</b>
<b class="nc"><i class="no-highlight">78</i>&nbsp;            this.killer = null;</b>
<i class="no-highlight">79</i>&nbsp;        }
<b class="nc"><i class="no-highlight">80</i>&nbsp;        if (!isAlive) {</b>
<b class="nc"><i class="no-highlight">81</i>&nbsp;            deathSprite.restart();</b>
<i class="no-highlight">82</i>&nbsp;        }
<b class="nc"><i class="no-highlight">83</i>&nbsp;        this.alive = isAlive;</b>
<i class="no-highlight">84</i>&nbsp;    }
<i class="no-highlight">85</i>&nbsp;
<i class="no-highlight">86</i>&nbsp;    /**
<i class="no-highlight">87</i>&nbsp;     * Returns the unit that caused the death of Pac-Man.
<i class="no-highlight">88</i>&nbsp;     *
<i class="no-highlight">89</i>&nbsp;     * @return &lt;code&gt;Unit&lt;/code&gt; iff the player died by collision, otherwise &lt;code&gt;null&lt;/code&gt;.
<i class="no-highlight">90</i>&nbsp;     */
<i class="no-highlight">91</i>&nbsp;    public Unit getKiller() {
<b class="nc"><i class="no-highlight">92</i>&nbsp;        return killer;</b>
<i class="no-highlight">93</i>&nbsp;    }
<i class="no-highlight">94</i>&nbsp;
<i class="no-highlight">95</i>&nbsp;    /**
<i class="no-highlight">96</i>&nbsp;     * Sets the cause of death.
<i class="no-highlight">97</i>&nbsp;     *
<i class="no-highlight">98</i>&nbsp;     * @param killer is set if collision with ghost happens.
<i class="no-highlight">99</i>&nbsp;     */
<i class="no-highlight">100</i>&nbsp;    public void setKiller(Unit killer) {
<b class="nc"><i class="no-highlight">101</i>&nbsp;        this.killer =  killer;</b>
<i class="no-highlight">102</i>&nbsp;    }
<i class="no-highlight">103</i>&nbsp;
<i class="no-highlight">104</i>&nbsp;    /**
<i class="no-highlight">105</i>&nbsp;     * Returns the amount of points accumulated by this player.
<i class="no-highlight">106</i>&nbsp;     *
<i class="no-highlight">107</i>&nbsp;     * @return The amount of points accumulated by this player.
<i class="no-highlight">108</i>&nbsp;     */
<i class="no-highlight">109</i>&nbsp;    public int getScore() {
<b class="nc"><i class="no-highlight">110</i>&nbsp;        return score;</b>
<i class="no-highlight">111</i>&nbsp;    }
<i class="no-highlight">112</i>&nbsp;
<i class="no-highlight">113</i>&nbsp;    @Override
<i class="no-highlight">114</i>&nbsp;    public Sprite getSprite() {
<b class="nc"><i class="no-highlight">115</i>&nbsp;        if (isAlive()) {</b>
<b class="nc"><i class="no-highlight">116</i>&nbsp;            return sprites.get(getDirection());</b>
<i class="no-highlight">117</i>&nbsp;        }
<b class="nc"><i class="no-highlight">118</i>&nbsp;        return deathSprite;</b>
<i class="no-highlight">119</i>&nbsp;    }
<i class="no-highlight">120</i>&nbsp;
<i class="no-highlight">121</i>&nbsp;    /**
<i class="no-highlight">122</i>&nbsp;     * Adds points to the score of this player.
<i class="no-highlight">123</i>&nbsp;     *
<i class="no-highlight">124</i>&nbsp;     * @param points
<i class="no-highlight">125</i>&nbsp;     *            The amount of points to add to the points this player already
<i class="no-highlight">126</i>&nbsp;     *            has.
<i class="no-highlight">127</i>&nbsp;     */
<i class="no-highlight">128</i>&nbsp;    public void addPoints(int points) {
<b class="nc"><i class="no-highlight">129</i>&nbsp;        score += points;</b>
<i class="no-highlight">130</i>&nbsp;    }
<i class="no-highlight">131</i>&nbsp;}
</div>
</pre>
</div>

<script type="text/javascript">
(function() {
    var msie = false, msie9 = false;
    /*@cc_on
      msie = true;
      @if (@_jscript_version >= 9)
        msie9 = true;
      @end
    @*/

    if (!msie || msie && msie9) {
        var codeBlock = document.getElementById('sourceCode');

        if (codeBlock) {
            hljs.highlightBlock(codeBlock);
        }
    }
})();
</script>

<div class="footer">
    
    <div style="float:right;">generated on 2022-05-22 18:55</div>
</div>
</body>
</html>
